using System;
using System.Collections.Generic;
using System.Text;

using System.IO;

using System.Windows.Forms;

using WMEncoderLib;

using HundredMilesSoftware.UltraID3Lib;

namespace Parsifal
{
    public class ManagePlaylistServer
    {

        public enum MNPLAYLIST_CHANGE_ACTION
        {
            MNPLAYLIST_REMOVE_ITEM,
            MNPLAYLIST_ADD_ITEM
        }

        public enum MNPLAYLIST_STREAM_STATE
        {
            MNPLAYLIST_STREAM_FILE,
            MNPLAYLIST_STREAM_LIVE
        }

        public enum MNPLAYLIST_TYPE_REQUESTED
        {
            MNPLAYLIST_TYPE_LOCAL,
            MNPLAYLIST_TYPE_EXTERN
        }


        //delegati
        public delegate void OnChangeBroadServer(string nickServer, PlaylistItem aPlaylistItem);

        public delegate void OnActivateSong(PlaylistItem aItem,PlaylistItem.PLI_TYPE aPLItemType);

        public delegate void OnDeactivatedSong(PlaylistItem aItem, PlaylistItem.PLI_TYPE aPLItemType);
        
        public delegate void OnEndedPlaylist();

        public delegate void OnChangedPlaylist(PlaylistItem aItem, MNPLAYLIST_CHANGE_ACTION aAction, int aIndexInFront);

        public delegate void OnCompletedInsertedElement();

        




        private PlaylistCollection iPlaylistCollection;
        private ManageEncoder iManageEncoder;

        private ManageSendDataServer iManageSendData;

        //logger
        Utility iUtility;
        private MNPLAYLIST_STREAM_STATE mState;

        public event OnActivateSong _OnActivatedSong;

        public event OnDeactivatedSong _OnDeactivatedSong;

        public event OnChangeBroadServer _OnChangeBroadServer;

        public event OnEndedPlaylist _OnEndedPlaylist;

        public event OnChangedPlaylist _OnChangedPlaylist;

        public event OnCompletedInsertedElement _OnCompletedInsertedElement;


    
        public ManagePlaylistServer(ManageEncoder aManageEncoder,Utility aUtility,ManageSendDataServer aManageSendData)
        {
            iPlaylistCollection = new PlaylistCollection();

            iManageEncoder = aManageEncoder;

            iUtility = aUtility;

            iManageSendData = aManageSendData;

            AddEventHandlerToManageEncoder();



            //Elementi temporanei

            //for (int i = 0; i < 1; i++)
            //{
            //    PlaylistItem aItem = new PlaylistItem();
            //    aItem.Artist = "daxweb" + i;
            //    aItem.Song = "Artigianalmente" + i;
            //    aItem.Duration = "3 min" + i;
            //    aItem.PhysicalPath = "C:\\seattle.wmv";
            //    aItem.isLocal = true;
            //    aItem.NickServer = "local";



            //    if (i == 0)
            //    {
            //        aItem.isActive = true;
                    
            //    }
            //    if (i == 4)
            //    {
            //        aItem.NickServer = "local";
            //        aItem.PhysicalPath = "C:\\seattle.wmv";
            //    }

            //    if (i == 5)
            //    {
            //        aItem.NickServer = "local";
            //        aItem.PhysicalPath = "C:\\seattle.wmv";
            //    }

            //    if (i == 6)
            //    {
            //        aItem.NickServer = "local";
            //        aItem.PhysicalPath = "C:\\seattle.wmv";
            //    }

            //    if (i == 9)
            //    {
            //        aItem.isLocal = false;
            //        aItem.NickServer = "daxweb";
            //        aItem.PhysicalPath = "C:\\3.mp3";
            //    }


            //    iManageEncoder.AddMediaSourceToEncoderCollection(aItem);

            //    this.AddPlaylistItem(aItem);

                
            //}

           


        }


        public PlaylistCollection PlaylistCollection
        {
            get
            {
                return iPlaylistCollection;
            }

        }

        public MNPLAYLIST_STREAM_STATE StreamState
        {
            get
            {
                return mState;
            }
            set
            {
                mState = value;
            }
        }

        public void LoadPlaylistFromFile()
        {
            
        }

        private ManageTag GetInfoOnID3Mp3(string percorsofile)
        {
            //nuova libreria ID3ULTRA
            UltraID3 ultraId3 = new UltraID3();
            ultraId3.Read(percorsofile);

            ID3v1Tag v1 = ultraId3.ID3v1Tag;
            ID3v23Tag v2 = ultraId3.ID3v23Tag;

            ManageTag iTag = new ManageTag() ;
            iTag.Artist = "Nessuna informazione";
            iTag.Song = " - ";
            iTag.Duration = new TimeSpan(0);
            iTag.Comment = "-";

            string v1p = v1.Album.Trim();
            string v2p = v2.Album.Trim();

            if (v1p != "")
            {
                iTag.Artist = v1.Artist;
                iTag.Song = v1.Title;
                iTag.Comment = v1.Comments;
            }

            if (v2p != "")
            {
                iTag.Artist = v2.Artist;
                iTag.Song = v2.Title;
                iTag.Comment = v2.Comments;
            }




            if (v1p == "" && v2p == "")
            {
                //formato : XXXXX - YYYYY.EXT
                string filepath = Path.GetFileName(percorsofile);


                int poitpos = filepath.IndexOf(".", filepath.Length - 4);
                
                filepath = filepath.Substring(0, poitpos);

                char[] charSeparators = new char[] { '-' };
                string[] aStr = filepath.Split(charSeparators);

                if (aStr[0].Trim() != "")
                {
                    iTag.Artist = aStr[0].ToString();
                }

                try
                {
                    if (aStr.Length >= 1)
                    {

                        iTag.Song = aStr[1].ToString();
                    }
                }
                catch { }

            }

            //check nome file


            //per entrambi
            iTag.Duration = ultraId3.Duration;


            
            return iTag;
        }

        public string CalculateTimeFromSeconds(int aSeconds)
        {
            string res;

            int minute = aSeconds / 60;
            


            if (minute >= 1)
            {
                int seconds = aSeconds % 60;
                
                res = minute.ToString() + ".";



                if (seconds < 10)
                {
                    res += "0" + seconds.ToString();
                }
                else
                {
                    res += seconds.ToString();
                }


            }
            else
            {
                res = "0." + aSeconds;

            }

            res += " min";

            return res;

        }

        public void AddPlaylistItem(PlaylistItem aItem)
        {
            try
            {

                if (aItem.Type == PlaylistItem.PLI_TYPE.PLI_FILE)
                {
                    //set information about IDTAG

                    ManageTag iTag = GetInfoOnID3Mp3(aItem.PhysicalPath);
                    aItem.Song = iTag.Song;
                    aItem.Artist = iTag.Artist;
                    //aItem.Duration = iTag.Duration.Minutes.ToString() + "." +
                    //    iTag.Duration.Seconds.ToString() + " min";
                    aItem.Duration = CalculateTimeFromSeconds((int)iTag.Duration.TotalSeconds);
                    aItem.Seconds = (int)iTag.Duration.TotalSeconds;

                }
                else if (aItem.Type == PlaylistItem.PLI_TYPE.PLI_LIVE)
                {
                    //TODO : da cambiare
                    aItem.Song = "OnAir";
                    aItem.Artist = "Dj";
                }


                    iPlaylistCollection.AddElementToCollection(aItem);
                

                //lancio l'evento
                if (_OnChangedPlaylist != null)
                {
                    _OnChangedPlaylist(aItem, MNPLAYLIST_CHANGE_ACTION.MNPLAYLIST_ADD_ITEM,-1);
                }
            }
            catch (Exception err)
            {
                throw new Exception("Errore nell'inserimento di un nuovo elemento della playlist");
            }
        }


        public PlaylistItem AddPlaylistItem(string filepath,MNPLAYLIST_TYPE_REQUESTED aType,int aIndex)
        {
            try
            {


                //set information about IDTAG
                PlaylistItem aItem = new PlaylistItem();
                aItem.PhysicalPath = filepath;


                ManageTag iTag = GetInfoOnID3Mp3(aItem.PhysicalPath);
                aItem.Song = iTag.Song;
                aItem.Artist = iTag.Artist;
                aItem.Duration = CalculateTimeFromSeconds((int)iTag.Duration.TotalSeconds);
                aItem.Seconds = (int)iTag.Duration.TotalSeconds;


                switch (aType)
                {
                    case MNPLAYLIST_TYPE_REQUESTED.MNPLAYLIST_TYPE_LOCAL:
                        {
                            aItem.isLocal = true;
                            aItem.NickServer = "local";
                        }
                        break;
                    case MNPLAYLIST_TYPE_REQUESTED.MNPLAYLIST_TYPE_EXTERN:
                        {
                        } break;
                    default:
                        break;

                }



                iPlaylistCollection.AddElementToCollection(aItem);

                //lancio l'evento
                if (_OnChangedPlaylist != null)
                {
                    _OnChangedPlaylist(aItem, MNPLAYLIST_CHANGE_ACTION.MNPLAYLIST_ADD_ITEM,aIndex);
                }

                return aItem;
            }
            catch (Exception err)
            {

                throw new Exception("Errore nell'inserimento di un nuovo elemento della playlist");
            }
        }



        public void RemovePlaylistItem(PlaylistItem aItem)
        {
            //try
            //{
                iPlaylistCollection.RemoveElementToCollection(aItem.Index);

                //lancio l'evento remove da gestire nel form1
                if (_OnChangedPlaylist != null)
                {
                    _OnChangedPlaylist(aItem, MNPLAYLIST_CHANGE_ACTION.MNPLAYLIST_REMOVE_ITEM,-1);
                }

            //}
            //catch (Exception err)
            //{
            //    throw new Exception("Errore nella rimozione di un elemento della playlist");
            //}
        }

        public PlaylistItem[] GetCollectionPlaylistItem()
        {
            try
            {


                int newsize = this.PlaylistCollection.Array.Count;

                PlaylistItem[] aTemp = new PlaylistItem[1] ;
                System.Array.Resize(ref aTemp, newsize);

                this.PlaylistCollection.Array.CopyTo(aTemp);


               

                return aTemp;
            }
            catch (Exception err)
            {

                throw err;
            }
        }

        public PlaylistItem GetActivePlaylistItem()
        {
           
                try
                {
                    PlaylistItem res = null;
                    for (int i = 0; i < this.PlaylistCollection.Array.Count; i++)
                    {
                        res = (PlaylistItem)this.PlaylistCollection.Array[i];
                        if (res.isActive == true)
                        {
                            return res;
                        }
                    }

                    return res;
                }
                catch (Exception err)
                {

                    throw new Exception("Errore nell'identificazione della song activa");
                }

          
        }


        //modifica del 30/04
        public PlaylistItem GetPlaylistItem(string path,int cazzone)
        {

            try
            {
                PlaylistItem res = null;
                for (int i = 0; i < this.PlaylistCollection.Array.Count; i++)
                {
                    res = (PlaylistItem)this.PlaylistCollection.Array[i];
                    if (res.PhysicalPath == path)
                    {
                        return res;
                    }
                }

                return res;
            }
            catch (Exception err)
            {

                throw new Exception("Errore nell'estrazione dalla collection della playlist relativa al path");
            }

        }

        public PlaylistItem GetPlaylistItem(int aIndex)
        {
            
                try
                {
                    PlaylistItem res = null;
                    for (int i = 0; i < this.PlaylistCollection.Array.Count; i++)
                    {
                        res = (PlaylistItem)this.PlaylistCollection.Array[i];
                        if (res.Index == aIndex)
                        {
                            return res;
                        }
                    }

                    return res;
                }
                catch (Exception err)
                {

                    throw new Exception("Errore nell'estrazione dalla collection della playlist relativa all'ID");
                }

            }


        public PlaylistItem GetPlaylistItem(string groupname)
        {

            try
            {
                PlaylistItem res = null;
                for (int i = 0; i < this.PlaylistCollection.Array.Count; i++)
                {
                    res = (PlaylistItem)this.PlaylistCollection.Array[i];
                    if (res.GroupName == groupname)
                    {
                        return res;
                    }
                }

                return res;
            }
            catch (Exception err)
            {

                throw new Exception("Errore nell'estrazione dalla collection della playlist relativa all'groupname");
            }

        }

        public PlaylistItem GetPlaylistItem(string artist, string song)
        {
            try
            {
                PlaylistItem res = null;
                for (int i = 0; i < this.PlaylistCollection.Array.Count; i++)
                {
                    res = (PlaylistItem)this.PlaylistCollection.Array[i];
                    if (res.Artist == artist & res.Song ==song)
                    {

                        return res;
                    }
                }

                return res;
            }
            catch (Exception err)
            {
                throw new Exception("Errore nell'identificazione del playlistitem partendo da artista e song");
            }
        }

        public void AddEventHandlerToManageEncoder()
        {
            try
            {
                iManageEncoder._OnBroadServerStart +=new ManageEncoder.OnBroadServerStart(iManageEncoder__OnBroadServerStart);
                iManageEncoder._OnBroadServerStop +=new ManageEncoder.OnBroadServerStop(iManageEncoder__OnBroadServerStop);
                iManageEncoder._OnClientConnect += new ManageEncoder.OnClientConnect(iManageEncoder__OnClientConnect);
                iManageEncoder._OnClientDisconnect +=new ManageEncoder.OnClientDisconnect(iManageEncoder__OnClientDisconnect);
                iManageEncoder._OnSourceStateStart +=new ManageEncoder.OnSourceStateStart(iManageEncoder__OnSourceStateStart);
                iManageEncoder._OnSourceStateStop +=new ManageEncoder.OnSourceStateStop(iManageEncoder__OnSourceStateStop);

            }
            catch (Exception err)
            {
                
                throw new Exception("Errore nel'inserimento del gestore eventi del manage Encoder");
            }
        }




        //sezione handler ManageEncoder
        public void iManageEncoder__OnBroadServerStart()
        {
            iUtility.LogEvent("MANAGE PLAYLIST S : Enter OnBroadServerStart", NLog.LogLevel.Info);

        }

        public void iManageEncoder__OnBroadServerStop()
        {
            DeactivateAllSong();

            iUtility.LogEvent("MANAGE PLAYLIST S : Enter OnBroadServerStop", NLog.LogLevel.Info);
        }

        public void iManageEncoder__OnClientConnect(string IPAddr)
        {
            iUtility.LogEvent("MANAGE PLAYLIST S : Enter OnClientConnect", NLog.LogLevel.Info);
        }

        public void iManageEncoder__OnClientDisconnect(string IPAddr)
        {
            iUtility.LogEvent("MANAGE PLAYLIST S : Enter OnClientDisconnect", NLog.LogLevel.Info);
        }



        public void iManageEncoder__OnSourceStateStart(WMENC_SOURCE_TYPE enumType, short iIndex, string sSourceGroup,IWMEncSourceGroup aSrcGroup)
        {
            try
            {

                string bt1, bt2, bt3;

                IWMEncSource iSource = aSrcGroup.get_Source(enumType, 0);
                bt3 = iSource.GetInput(out bt1,out bt2);

                PlaylistItem aPLItem = iPlaylistCollection.GetPlaylistItem(iIndex, sSourceGroup, bt3);

                



                //if (aPLItem.Type == PlaylistItem.PLI_TYPE.PLI_FILE)
                //{

                //    mState = MNPLAYLIST_STREAM_STATE.MNPLAYLIST_STREAM_FILE;

                //}
                //else
                //{
                //    mState = MNPLAYLIST_STREAM_STATE.MNPLAYLIST_STREAM_LIVE;
                //}

               
                //****imposto le informazioni per la visualizzazione su Media Player....
                //iManageEncoder.Encoder.DisplayInfo.Author = aPLItem.Artist;
                //iManageEncoder.Encoder.DisplayInfo.Title = aPLItem.Song;
                //iManageEncoder.Encoder.DisplayInfo.Description = "Informazioni inviate da Dj xxx";
                




                aPLItem.isActive = true;


                if (_OnActivatedSong != null)
                {
                    _OnActivatedSong(aPLItem,aPLItem.Type);
                }

                iUtility.LogEvent("MANAGE PLAYLIST S : Enter OnSourceStateStart :: dati " + aPLItem.PhysicalPath, NLog.LogLevel.Info);



            }
            catch (Exception err)
            {
                iUtility.LogEvent("MANAGE PLAYLIST S : Errore  OnSourceStateStart :: err " + err.Message, NLog.LogLevel.Error);

                throw err;
            }
        }

        public void iManageEncoder__OnSourceStateStop(WMENC_SOURCE_TYPE enumType, short iIndex, string sSourceGroup, IWMEncSourceGroup aSrcGroup)
        {
            try
            {

                string bt1, bt2, bt3;

                IWMEncSource iSource = aSrcGroup.get_Source(enumType, 0);
                bt3 = iSource.GetInput(out bt1, out bt2);

                PlaylistItem aPLItem = iPlaylistCollection.GetPlaylistItem(iIndex, sSourceGroup, bt3);



                //aPLItem.isActive = false;

                //controllo se inviare lo speacker off
                //if (aPLItem.Type == ManagePlaylistServer.MNPLAYLIST_STREAM_STATE.MNPLAYLIST_STREAM_LIVE)
                //{
                //    iManageSendData._SendAllSpeackerOff(
                //        iClientPlusCollection.GetSocketActiveFromCollection());

                //}


                aPLItem.isActive = false;
                //CheckNextPlaylistItem();


                if (_OnDeactivatedSong != null)
                {
                    _OnDeactivatedSong(aPLItem, aPLItem.Type);
                }

                iUtility.LogEvent("MANAGE PLAYLIST S : Enter OnSourceStateStop :: dati " + aPLItem.PhysicalPath, NLog.LogLevel.Info);



            }
            catch (Exception err)
            {

                throw err;
            }
            //finally
            //{
            //    string bt3 = "";
            //    PlaylistItem aPLItem = iPlaylistCollection.GetPlaylistItem(iIndex, sSourceGroup, bt3);
            //    if (_OnDeactivatedSong != null)
            //    {
            //        _OnDeactivatedSong(aPLItem, aPLItem.Type);
            //    }

            //    iUtility.LogEvent("MANAGE PLAYLIST S : Finally OnSourceStateStop :: dati " + bt3, NLog.LogLevel.Info);
            //}
        }

        private void DeactivateAllSong()
        {
            //metto tutte le song tu active=false
            for (int i = 0; i<iPlaylistCollection.Array.Count; i++)
            {
                PlaylistItem dxT = (PlaylistItem)iPlaylistCollection.Array[i];
                if (dxT != null)
                {
                    
                    dxT.isActive = false;

                    _OnDeactivatedSong(dxT, dxT.Type);
                }
            }


        }


        

        public void CheckNextPlaylistItem()
        {
            //try
            //{
            //    PlaylistItem iPLnext;

            //    PlaylistItem iTemp = iPlaylistCollection.GetActivePlaylistItem();
            //    if (iTemp == null)
            //        throw new Exception("Errore nell'estrazione della song attiva");

            //    int countItem = iPlaylistCollection.Array.Count;
            //    if (iTemp.Index<countItem - 1)
            //    {
            //        iPLnext = iPlaylistCollection.GetPlaylistItem(iTemp.Index + 1);
            //    }
            //    else
            //    {
            //        iPLnext = iPlaylistCollection.GetPlaylistItem(0);
            //    }
            //    if (iPLnext != null)
            //    {
            //        string nickServer = iPLnext.NickServer;
            //        if (nickServer != "local")
            //        {
            //            //TODO: invia l'evento per la creazione di un nuovo server

            //            iUtility.LogEvent("MANAGE PLAYLIST :: EVENTO : OnChangeBroadServer :: dati " + nickServer + " " +
            //                iPLnext.PhysicalPath + " " + iPLnext.Index, NLog.LogLevel.Info);

            //            if (_OnChangeBroadServer != null)
            //            {

            //                iManageEncoder.stop_streaming_server();

            //                _OnChangeBroadServer(nickServer, iPLnext);

            //            }
            //        }
            //        else
            //        {
                        
                      


            //            //avanza la song attiva



            //            iTemp.isActive = false;

            //            iPLnext.isActive = true;

            //            iManageEncoder.SetActiveSource(iPLnext);

            //            iUtility.LogEvent("MANAGE PLAYLIST :: ACTIVE SONG :: data ::" + iPLnext.Index + " " + iPLnext.PhysicalPath + " " + iPLnext.Song, NLog.LogLevel.Info);
            //        }

            //    }
            //    else
            //    {
            //        //playlist finita
            //        //lancio un evento
            //        iUtility.LogEvent("MANAGE PLAYLIST :: ENDED PLAYLIST :: OK", NLog.LogLevel.Info);
                    
            //        if (_OnEndedPlaylist != null)
            //        {
            //            _OnEndedPlaylist();
            //        }

            //    }

            //}
            //catch (Exception err)
            //{
            //    iUtility.LogEvent("MANAGE PLAYLIST :: ERROR E :: " + err.Message, NLog.LogLevel.Error);
            //    throw err;
            //}
        }


        public string[] OpenFileDialogBoxExt()
        {

            string[] ret = { "" };

            try
            {
                //OpenFileDialog dlgOpenFile = new OpenFileDialog();
                //dlgOpenFile.InitializeLifetimeService();

                //dlgOpenFile.Filter = "Mp3 (*.mp3)|*.mp3|Media Audio (*.wma)|*.wma|Media Video (*.wmv)|*.wmv|All files (*.*)|*.*";

                //dlgOpenFile.Multiselect = true;


                

                OpenFileDialog opd = new OpenFileDialog();
                opd.InitializeLifetimeService();

                opd.Title = "Choose your mp3 file to add in your playlist";
                opd.DefaultExt = ".mp3";

                opd.Filter = "Mp3 (*.mp3)|*.mp3|Media Audio (*.wma)|*.wma|Media Video (*.wmv)|*.wmv|All files (*.*)|*.*";




                if (opd.ShowDialog() == DialogResult.OK)
                {

                    // If ReadOnlyChecked is true, uses the OpenFile method to
                    // open the file with read/only access.
                    return opd.FileNames;

                }
                else
                {
                    
                    return ret;
                }

            }
            catch (Exception err)
            {
                //this.LogEvent("Utility :: Errore nell'apertura del file selezionato ", LogLevel.Error);

                throw new Exception("Errore nell'apertura del file selezionato...");

            }

            return ret;
        }

        public PlaylistItem AddPlaylistItemFromServer()
        {
            
            PlaylistItem resItem = null;
            
            try
            {



                //string[] aFile = iUtility.OpenFileDialogBox();
                string[] aFiles = OpenFileDialogBoxExt();


                for (int i = 0; i < aFiles.Length; i++)
                 {
                     string file = aFiles[i];
                     if (file != "")
                     {

                         iUtility.LogEvent("Pre Add Play" +file);


                         PlaylistItem aItem = this.AddPlaylistItem(file, MNPLAYLIST_TYPE_REQUESTED.MNPLAYLIST_TYPE_LOCAL, -1);

                         iUtility.LogEvent("Pre AddMedia");

                         iManageEncoder.AddMediaSourceToEncoderCollection(aItem);
                         iUtility.LogEvent("Post ADd M;edia");

                         //OnRoll
                         if (_OnCompletedInsertedElement != null)
                         {
                             _OnCompletedInsertedElement();
                         }



                         iUtility.LogEvent("MANAGE PLAYLIST :: aggiunto nuovo playlist alla collection : dati " + aItem.Artist + " "
                             + aItem.Song + " " + aItem.PhysicalPath + " " + aItem.GroupName, NLog.LogLevel.Info);


                         resItem = aItem;
                     }
                     else
                     {
                         resItem= null;
                     }

                    
                 }

            }
            catch (Exception err)
            {
                iUtility.LogEvent("Errore nell'inserimento di un nuovo playlistItem dal server", NLog.LogLevel.Error);
                throw new Exception("Errore nell'inserimento di un nuovo playlistItem dal server. " + err.Message) ;
            }

            return resItem;
        }


        public PlaylistItem AddPlaylistItemFromServerEx()
        {

            PlaylistItem resItem = null;

            try
            {


                string[] aFile = iUtility.OpenFileDialogBox();

                for (int i = 0; i < aFile.Length; i++)
                {
                    string file = aFile[i];
                    if (file != "")
                    {




                        PlaylistItem aItem = this.AddPlaylistItem(file, MNPLAYLIST_TYPE_REQUESTED.MNPLAYLIST_TYPE_LOCAL, -1);

                        //-----------evito di aggiungerlo nel media encoder
                        //iManageEncoder.AddMediaSourceToEncoderCollection(aItem);

                        //OnRoll
                        if (_OnCompletedInsertedElement != null)
                        {
                            _OnCompletedInsertedElement();
                        }





                        iUtility.LogEvent("MANAGE PLAYLIST EX:: aggiunto nuovo playlist alla collection : dati " + aItem.Artist + " "
                            + aItem.Song + " " + aItem.PhysicalPath + " " + aItem.GroupName, NLog.LogLevel.Info);


                        resItem = aItem;
                    }
                    else
                    {
                        resItem = null;
                    }


                }

            }
            catch (Exception err)
            {
                iUtility.LogEvent("Errore nell'inserimento di un nuovo playlistItem dal server", NLog.LogLevel.Error);
                throw new Exception("Errore nell'inserimento di un nuovo playlistItem dal server. " + err.Message);
            }

            return resItem;
        }
       

       
           
    }

    public class ManageTag
    {
        public string Artist;
        public string Song;
        public TimeSpan Duration;
        public string Comment;
    }
}
